home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11839 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: nntp.teleport.com!usenet
  2. From: GHouck <hksys@teleport.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Converting numbers to strings?
  5. Date: Tue, 26 Mar 1996 14:51:11 -0800
  6. Organization: systems hk
  7. Message-ID: <315874DF.4357@teleport.com>
  8. References: <4j4agq$85h@mozo.cc.purdue.edu>
  9. NNTP-Posting-Host: ip-pdx02-38.teleport.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.01 (WinNT; I)
  14.  
  15. Brian R. Jones wrote:
  16. > I am pretty familiar with the functions that convert strings into
  17. > numbers, but am totally unfamiliar with the reverse process.  What
  18. > I am looking to do is have a program save several files with the
  19. > same basic file root, but differentiated by a number.  For example
  20. > I have a loop in my code that varies a variable, q, that varies in
  21. > increments of 100.  Each time through the loop, I would like to save
  22. > a data file called:
  23. >                 out1q100.dat
  24. >                 out1q200.dat
  25. >                 out1q300.dat
  26. > It seems that if I can simply convert the floating point variable, q,
  27. > to a string, I could use strcat to add it to the basic filename root,
  28. > out1q.  Is there a simple way to do this?  I haven't found anything
  29. > in the string(s).h file that would do the trick.  Many thanks!Brian,
  30. You might try:
  31.  
  32.   strcpy( filePrefix,"out1q" );
  33.   ...
  34.   sprintf( fileName,"%s%03d.dat",filePrefix,fileNumber );
  35.   fileNumber += 100;
  36.   ...
  37.  
  38. Yours, Geoff Houck
  39.